<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title id="divTitle"> 批量添加期刊文献医案 </title>
  <link rel="stylesheet" type="text/css" href="/css/style.css" />

  <style type="text/css">
    *, body {
      margin: 0px;
      font-family: '微软雅黑',serif;
    }
  </style>
  <script src="/js/generic.js"></script>

  <script type="text/javascript" src="/js/EasyUI/jquery.min.js"></script>
  <script type="text/javascript" src="/js/EasyUI/jquery.ui.widget.js"></script>
  <script type="text/javascript" src="/js/EasyUI/jquery.iframe-transport.js"></script>
  <script type="text/javascript" src="/js/EasyUI/jquery.fileupload.js"></script>
  <script type="text/javascript" src="/js/EasyUI/jquery.fileupload-process.js"></script>
  <script type="text/javascript" src="/js/EasyUI/jquery.fileupload-validate.js"></script>
  <script type="text/javascript" src="/js/EasyUI/jquery.fileupload-ui.js"></script>


</head>

<body>
<form id="filePost" method="post" enctype="multipart/form-data" onsubmit="return false;">
  <table class="maintable">
    <tr>
      <td class="rightmaintd" valign="top">

        <div style="width:920px;margin:10px auto;"> <a href="/qikan">&lt;  返回</a> </div>
        <div style="margin-left:300px;margin-top:20px">
          <span>上传文件：&nbsp;&nbsp;</span>
          <input id="fileUpload" type="file" name="myxxFile" accept=".xls, .xlsx"/>
          <a target="_blank" data-icon="arrow-down" class="btn btn-green" href="/batchUpload/wenxianYian.xlsx">下载模板</a>
        </div>
        <div style="margin-left:300px;margin-top:20px">
          <input type="button" value="提&nbsp;&nbsp;交" class="denglubtn" onclick="save();">
        </div>
        <div id="progress" style="margin-left:300px;margin-top:20px">
          <div class="progressbar" style="width:0%"></div>
        </div>
        <br />
        <table border="1" id="tab1" style="margin-left:300px"></table>
        <table class="logintable" cellpadding="8" style="margin-top:20px;"></table>
      </td>
    </tr>
  </table>
</form>
</body>
<script type="text/javascript">
  function save() {
    const fileInput = document.getElementById('fileUpload');
    const file = fileInput.files[0];
    if (!file) {
      alert('请先上传文件');
      return;
    }
    const formData = new FormData();
    formData.append('file', file);
    fetch('/qikan/batch/', {
      method: 'POST',
      body: formData
    })
            .then(response => response.json())
            .then(data => {
              alert(data.message);
              window.location.href="/qikan";
            })
            .catch(error => {
              console.error('Error:', error);
              alert('发生错误！请检查文件内容与格式！');
            });
  }
</script>
</html>